import 'package:flutter/material.dart';

/// 左右箭头视图
class ArrowLeftRightView extends StatelessWidget {
  final String? title;
  final TextStyle titleStyle;

  /// 视图上下左右间距
  final EdgeInsetsGeometry? padding;

  /// 文本与图标之间的间距 默认8pt
  final double spacing;
  final Widget arrowIcon;
  final bool showOnRight;
  const ArrowLeftRightView(
      {Key? key,
      this.title,
      this.titleStyle =
          const TextStyle(color: Color(0xff009cfe), fontSize: 12.0),
      this.arrowIcon = const Icon(
        Icons.arrow_forward_ios,
        color: Color(0xff009cfe),
        size: 10,
      ),
      this.showOnRight = true,
      this.padding,
      this.spacing = 8.0})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: padding,
      child: Row(
        children: _children,
      ),
    );
  }

  List<Widget> get _children {
    if (title == null || title!.isEmpty) {
      return [];
    }
    final textWidget = Text(
      title!,
      style: titleStyle,
    );
    final spacerWidget = SizedBox(
      width: spacing,
    );
    if (showOnRight) {
      return [textWidget, spacerWidget, arrowIcon];
    } else {
      return [arrowIcon, spacerWidget, textWidget];
    }
  }
}
